/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.gwt.apps.client.user;

import net.bioteam.appweb.gwt.apps.client.StaticHolder;

import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;

public class TemplatePanel extends SectionStack
{

	public TemplatePanel()
	{
		super();
		//setBorder("3px solid dark");
		setWidth(TemplateGrid.TemplateGridWidth);
		setHeight100();

		
		SectionStackSection section = new SectionStackSection();
		section.setCanCollapse(false);
		section.setExpanded(true);
		
		
		Img info=new Img("[SKIN]/actions/help.png");
		info.setWidth(18);
		info.setHeight(18);
		info.setPrompt("<p>Double Click to start Editing.</p>");
		info.setHoverWidth(200);
		
		ImgButton refresh = new ImgButton();
		refresh.setSrc("[SKIN]actions/refresh.png");
		refresh.setSize(16);
		refresh.setShowFocused(false);
		refresh.setShowRollOver(false);
		refresh.setShowDown(false);
		refresh.setPrompt("reload");
		refresh.addClickHandler(new ClickHandler()
		{

			public void onClick(ClickEvent event)
			{
				StaticHolder.getTemplateGrid().reload();
			}
		});
		

		ImgButton delete = new ImgButton();
		delete.setSrc("[SKIN]actions/remove.png");
		delete.setSize(16);
		delete.setShowFocused(false);
		delete.setShowRollOver(false);
		delete.setShowDown(false);
		delete.setPrompt("Click to remove selected templates");
		delete.addClickHandler(new ClickHandler()
		{

			public void onClick(ClickEvent event)
			{

				final TemplateGrid tGrid = StaticHolder.getTemplateGrid();
				if (tGrid.getSelection().length == 0)
				{
					SC.say("No template is selected");
				} else
				{
					BooleanCallback callback = new BooleanCallback()
					{

						public void execute(Boolean value)
						{
							if (value != null && value)
							{
								tGrid.removeSelectedData();
							}
						}

					};
					SC.confirm(tGrid.getSelection().length + " selected templates will be deleted", callback);
				}

				// StaticHolder.jobGrid.reload();
			}
		});
		
		

		
		TemplateGrid tGrid = new TemplateGrid();
		StaticHolder.templateGrid = tGrid;
		
		section.setControls(info, refresh, delete);
		section.setItems(tGrid);
		this.setSections(section);
		
	}
}
